<?php

/**
 * This is the model class for table "ticket_status".
 *
 * The followings are the available columns in table 'ticket_status':
 * @property integer $id
 * @property string $status
 * @property string $start_date
 * @property string $start_time
 * @property string $stop_date
 * @property string $stop_time
 * @property string $report_date
 * @property string $report_time
 * @property string $current_date
 * @property string $current_time
 * @property string $remarks
 * @property integer $ticket_id
 */
class TicketStatus extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ticket_status';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ticket_id', 'required'),
			array('ticket_id', 'numerical', 'integerOnly'=>true),
			array('status', 'length', 'max'=>45),
			array('remarks', 'length', 'max'=>600),
			array('start_date, start_time, stop_date, stop_time, report_date, report_time, current_date, current_time', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, status, start_date, start_time, stop_date, stop_time, report_date, report_time, current_date, current_time, remarks, ticket_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'ticket' => array(self::BELONGS_TO, 'Ticket', 'ticket_id'),
			
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'status' => 'Status',
			'start_date' => 'Start Date',
			'start_time' => 'Start Time',
			'stop_date' => 'Stop Date',
			'stop_time' => 'Stop Time',
			'report_date' => 'Report Date',
			'report_time' => 'Report Time',
			'current_date' => 'Current Date',
			'current_time' => 'Current Time',
			'remarks' => 'Remarks',
			'ticket_id' => 'Ticket',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		//$criteria->compare('id',$this->id);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('start_date',$this->start_date,true);
		$criteria->compare('start_time',$this->start_time,true);
		$criteria->compare('stop_date',$this->stop_date,true);
		$criteria->compare('stop_time',$this->stop_time,true);
		$criteria->compare('report_date',$this->report_date,true);
		$criteria->compare('report_time',$this->report_time,true);
		$criteria->compare('current_date',$this->current_date,true);
		$criteria->compare('current_time',$this->current_time,true);
		$criteria->compare('remarks',$this->remarks,true);
	    	$criteria->compare('t.id',$this->id);
		$criteria->compare('ticket.ticket_name',$this->ticket_id, true);
		$criteria->compare('t.id',$this->id);
		

$criteria->with=array('ticket');
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TicketStatus the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
